import 'package:chop/Model/order_entity.dart';
import 'package:chop/common/DateUtils.dart';
import 'package:chop/common/StringUtils.dart';
import 'package:chop/view/Driver/riderOrderInfo.dart';
import 'package:chop/view/home/place_an_order/Buying_order.dart';
import 'package:chop/widgets/TextSizeWidget.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

Widget getOrderItem(context, {orderData data}) {
  return GestureDetector(
    child: Container(
      width: double.infinity,
//    padding: EdgeInsets.all(5),
      margin: EdgeInsets.fromLTRB(10, 5, 10, 5),
      decoration: BoxDecoration(
//        border: z,
          borderRadius: BorderRadius.all(Radius.circular(10)),
          color: Colors.white),
      child: Row(
        children: <Widget>[
          Expanded(
            child: Column(
              children: <Widget>[
                getTitle(context, data),
                Container(
                  width: double.infinity,
                  padding: EdgeInsets.only(left: 10, bottom: 5),
                  child: Row(
                    children: <Widget>[
                      Icon(
                        Icons.access_time,
                        size: 15,
                      ),
                      FixedSizeText(
                        "  ${DateUtils.getStfDate(data.createTime)}",
                        textAlign: TextAlign.left,
                        overflow: TextOverflow.ellipsis,
                        style: TextStyle(),
                      )
                    ],
                  ),
                ),
                Container(
                  width: double.infinity,
                  padding: EdgeInsets.only(left: 10, bottom: 5),
                  child: Row(
                    children: <Widget>[
                      Icon(
                        Icons.subdirectory_arrow_right,
                        size: 15,
                        color: Colors.greenAccent,
                      ),
                      Container(
                        width: 5,
                      ),
                      Expanded(
                        child: FixedSizeText(
                          "${data.begin}",
                          textAlign: TextAlign.left,
                          maxLines: 4,
//                        overflow: TextOverflow.ellipsis,
                          style: TextStyle(),
                        ),
                      )
                    ],
                  ),
                ),
                Container(
                  width: double.infinity,
                  padding: EdgeInsets.only(left: 10, bottom: 5),
                  child: Row(
                    children: <Widget>[
                      Icon(
                        Icons.subdirectory_arrow_left,
                        size: 15,
                        color: Colors.redAccent,
                      ),
                      Container(
                        width: 5,
                      ),
                      Expanded(
                        child: FixedSizeText(
                          "${data.end}",
                          textAlign: TextAlign.left,
                          overflow: TextOverflow.ellipsis,
                          style: TextStyle(),
                        ),
                      )
                    ],
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    ),
    onTap: () {
      print("点击了订单");
      Get.to(RiderOrderInfo(
        uuid: data.uuid,
      ));
    },
  );
}

Widget getTitle(context, orderData data) {
  if (data.status == "2") {
    return Row(
      children: <Widget>[
        Expanded(
          child: Container(
            padding: EdgeInsets.all(10),
            child: FixedSizeText(
              getOrderType(data.orderType),
              textAlign: TextAlign.left,
              style: TextStyle(fontSize: 18),
            ),
          ),
        ),
      ],
    );
  } else if (data.status == "3") {
    return Row(
      children: <Widget>[
        Expanded(
          child: Container(
            padding: EdgeInsets.all(10),
            child: FixedSizeText(
              getOrderType(data.orderType),
              textAlign: TextAlign.left,
              style: TextStyle(fontSize: 18),
            ),
          ),
        ),
      ],
    );
  } else {
    return Container();
  }
}

String getOrderType(String type) {
  switch (type) {
    case "0":
      return "帮我送";
    case "1":
      return "帮我取";
    case "2":
      return "帮我买";
  }
}

getInfo(orderData data) {
  return ListView(children: <Widget>[
    Container(
      height: 10,
    ),
    getColumn("订单信息",
        child: Column(
          children: <Widget>[
            Container(
              padding: EdgeInsets.fromLTRB(15, 5, 15, 0),
              child: Row(
                children: <Widget>[
                  Expanded(
                    child: Column(
                      children: <Widget>[
                        Row(
                          children: <Widget>[
                            Container(
//                        width: double.infinity,
                              padding: EdgeInsets.only(top: 5, bottom: 5),
                              child: FixedSizeText(
                                "订单号：${data.uuid}",
                                textAlign: TextAlign.start,
                                style: TextStyle(
                                    fontSize: 16, fontWeight: FontWeight.bold),
                              ),
                            )
                          ],
                        ),
                        Row(
                          children: <Widget>[
                            Container(
//                        width: double.infinity,
                              padding: EdgeInsets.only(top: 5, bottom: 5),
                              child: FixedSizeText(
                                "订单状态：${getStatus(data.status)}",
                                textAlign: TextAlign.start,
                                style: TextStyle(
                                  fontSize: 16,
                                ),
                              ),
                            )
                          ],
                        ),
                        Container(
                          padding: EdgeInsets.only(top: 5, bottom: 5),
                          child: Row(
                            children: <Widget>[
                              Icon(
                                Icons.subdirectory_arrow_right,
                                size: 15,
                                color: Colors.greenAccent,
                              ),
                              Container(
                                width: 5,
                              ),
                              Expanded(
                                child: FixedSizeText(
                                  "${data.begin}",
                                  textAlign: TextAlign.left,
                                  maxLines: 4,
//                        overflow: TextOverflow.ellipsis,
                                  style: TextStyle(),
                                ),
                              )
                            ],
                          ),
                        ),
                        Container(
                          padding: EdgeInsets.only(top: 5, bottom: 5),
                          child: Row(
                            children: <Widget>[
                              Icon(
                                Icons.subdirectory_arrow_left,
                                size: 15,
                                color: Colors.redAccent,
                              ),
                              Container(
                                width: 5,
                              ),
                              Expanded(
                                child: FixedSizeText(
                                  "${data.end}",
                                  textAlign: TextAlign.left,
                                  overflow: TextOverflow.ellipsis,
                                  style: TextStyle(),
                                ),
                              )
                            ],
                          ),
                        ),
                        Row(
                          children: <Widget>[
                            Expanded(
                              child: Container(
                                child: FixedSizeText(
                                  "路程",
                                  style: TextStyle(color: Colors.black45),
                                ),
                              ),
                            ),
                            Expanded(
                              child: Container(
                                alignment: Alignment.topRight,
                                child: FixedSizeText("${data.distance} km   "),
                              ),
                            )
                          ],
                        ),
                        Row(
                          children: <Widget>[
                            Expanded(
                              child: Container(
                                child: FixedSizeText(
                                  "跑腿费",
                                  style: TextStyle(color: Colors.black45),
                                ),
                              ),
                            ),
                            Expanded(
                              child: Container(
                                alignment: Alignment.topRight,
                                child:
                                    FixedSizeText("${StringUtils.formatNum(data.money*0.8, 2)} \$   "),
                              ),
                            )
                          ],
                        ),
                      ],
                    ),
                    flex: 8,
                  ),
                ],
              ),
            ),
          ],
        )),
    getColumn("骑手信息",child: Column(
      children: <Widget>[
        Row(
          children: <Widget>[
            Expanded(
              child: Container(
                child: FixedSizeText(
                  "骑手",
                  style: TextStyle(color: Colors.black45),
                ),
              ),
            ),
            Expanded(
              child: Container(
                alignment: Alignment.topRight,
                child:
                FixedSizeText("${data.riderName}   "),
              ),
            )
          ],
        ),
        Row(
          children: <Widget>[
            Expanded(
              child: Container(
                child: FixedSizeText(
                  "订单开始时间",
                  style: TextStyle(color: Colors.black45),
                ),
              ),
            ),
            Expanded(
              child: Container(
                alignment: Alignment.topRight,
                child:
                FixedSizeText("${data.beginTime}   "),
              ),
            )
          ],
        ),
        Row(
          children: <Widget>[
            Expanded(
              child: Container(
                child: FixedSizeText(
                  "订单结束时间",
                  style: TextStyle(color: Colors.black45),
                ),
              ),
            ),
            Expanded(
              child: Container(
                alignment: Alignment.topRight,
                child:
                FixedSizeText("${data.endTime}   "),
              ),
            )
          ],
        ),
      ],
    )),
    getColumn("备注",child: FixedSizeText("${data.remark??''}   "))
  ]);
}
String getStatus(String status) {
  switch (status) {
    case "0":
      return "进行中";
    case "1":
      return "已完成";
    case "2":
      return "未付款";
    case "3":
      return "待接单";
  }
}